home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / RevRdist Folder / RevRdist / RevRdist src / syserr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-21  |  1.3 KB  |  57 lines  |  [TEXT/KAHL]

  1. /*
  2.  * Routine to look up the system error message corresponding to a
  3.  * result code
  4.  */
  5. static    Str255    eText;
  6. #define    ERRSTR    999                    /* Resource id of errlist STR# */
  7.  
  8. #include <Types.h>
  9. #include "C_config.h"
  10. StringPtr        syserrlist (OSErr);
  11.  
  12.  
  13.  
  14. /*
  15.  *=========================================================================
  16.  * syserrlist (n) - look up text for result code n
  17.  *    returns a pointer to a static Str255 containing the text
  18.  *=========================================================================
  19.  */
  20. StringPtr
  21. syserrlist (n)
  22. OSErr    n;
  23. {
  24.     Integer    i, j;
  25.     Longint    l;
  26.     int        len;
  27.  
  28.     for (i = 1;;i++)
  29.     {
  30.         /*
  31.          * The ERRSTR STR# resource should contain strings of the form:
  32.          * "-nnn:Error text"
  33.          * We search through all the STR#'s looking for one with a
  34.          * nnn which matches the error we're looking for.
  35.          */
  36.         eText[0] = 0;
  37.         GetIndString (eText, ERRSTR, i);
  38.         len = eText[0];
  39.         if (len == 0)
  40.             break;                    /* end of STR# or couldn't get rsrc */
  41.         for (j = 2; j < 6; j++)
  42.             if (eText[j] == ':' || eText[j] == ' ')
  43.                 break;
  44.         eText[0] = j - 1;                /* shorten string for StringToNum */
  45.         StringToNum (eText, &l);
  46.         eText[0] = len;
  47.         if (l == n)
  48.             break;
  49.     }
  50.     /*
  51.      * We either found the message, or we didn't
  52.      * In the latter case, we just return the number as text
  53.      */
  54.     if (eText[0] == 0)
  55.         NumToString ((long) n, eText);
  56.     return eText;
  57. }